﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_EventModelPropertyDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainStdEventModelDict");

            migrationBuilder.DropTable(
                name: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainStdDataModelDict");

            migrationBuilder.CreateTable(
                name: "MainDataModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    ProductTopicId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDataModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDataModelDict_MainProductTopic_ProductTopicId",
                        column: x => x.ProductTopicId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainEventModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    EventCode = table.Column<string>(type: "text", nullable: false),
                    EventName = table.Column<string>(type: "text", nullable: false),
                    TopicFullPath = table.Column<string>(type: "text", nullable: false),
                    ProductTopicId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainEventModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainEventModelDict_MainProductTopic_ProductTopicId",
                        column: x => x.ProductTopicId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainDataModelExtPropertyDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DataModelDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdPhrDictID = table.Column<Guid>(type: "uuid", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDataModelExtPropertyDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDataModelExtPropertyDict_MainDataModelDict_DataModelDic~",
                        column: x => x.DataModelDictId,
                        principalTable: "MainDataModelDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainDataModelExtPropertyDict_MainStdPhrDict_StdPhrDictID",
                        column: x => x.StdPhrDictID,
                        principalTable: "MainStdPhrDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainDataModelPropertyDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DataModelDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdPhrDictID = table.Column<Guid>(type: "uuid", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    PkFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NullableFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDataModelPropertyDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDataModelPropertyDict_MainDataModelDict_DataModelDictId",
                        column: x => x.DataModelDictId,
                        principalTable: "MainDataModelDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainDataModelPropertyDict_MainStdPhrDict_StdPhrDictID",
                        column: x => x.StdPhrDictID,
                        principalTable: "MainStdPhrDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainEventModelPropertyDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    EventModelDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdPhrDictID = table.Column<Guid>(type: "uuid", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    PkFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NullableFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainEventModelPropertyDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainEventModelPropertyDict_MainEventModelDict_EventModelDic~",
                        column: x => x.EventModelDictId,
                        principalTable: "MainEventModelDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainEventModelPropertyDict_MainStdPhrDict_StdPhrDictID",
                        column: x => x.StdPhrDictID,
                        principalTable: "MainStdPhrDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainDataModelDict_ProductTopicId",
                table: "MainDataModelDict",
                column: "ProductTopicId");

            migrationBuilder.CreateIndex(
                name: "IX_MainDataModelExtPropertyDict_DataModelDictId",
                table: "MainDataModelExtPropertyDict",
                column: "DataModelDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainDataModelExtPropertyDict_StdPhrDictID",
                table: "MainDataModelExtPropertyDict",
                column: "StdPhrDictID");

            migrationBuilder.CreateIndex(
                name: "IX_MainDataModelPropertyDict_DataModelDictId",
                table: "MainDataModelPropertyDict",
                column: "DataModelDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainDataModelPropertyDict_StdPhrDictID",
                table: "MainDataModelPropertyDict",
                column: "StdPhrDictID");

            migrationBuilder.CreateIndex(
                name: "IX_MainEventModelDict_ProductTopicId",
                table: "MainEventModelDict",
                column: "ProductTopicId");

            migrationBuilder.CreateIndex(
                name: "IX_MainEventModelPropertyDict_EventModelDictId",
                table: "MainEventModelPropertyDict",
                column: "EventModelDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainEventModelPropertyDict_StdPhrDictID",
                table: "MainEventModelPropertyDict",
                column: "StdPhrDictID");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainDataModelExtPropertyDict");

            migrationBuilder.DropTable(
                name: "MainDataModelPropertyDict");

            migrationBuilder.DropTable(
                name: "MainEventModelPropertyDict");

            migrationBuilder.DropTable(
                name: "MainDataModelDict");

            migrationBuilder.DropTable(
                name: "MainEventModelDict");

            migrationBuilder.CreateTable(
                name: "MainStdDataModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdDataModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdDataModelDict_MainProductTopic_TopicDictId",
                        column: x => x.TopicDictId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdEventModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    EventCode = table.Column<string>(type: "text", nullable: false),
                    EventName = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TopicFullPath = table.Column<string>(type: "text", nullable: false),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdEventModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdEventModelDict_MainProductTopic_TopicDictId",
                        column: x => x.TopicDictId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdModelAssocPhrDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StdModelDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdPhrDictID = table.Column<Guid>(type: "uuid", nullable: false),
                    NullableFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PkFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelAssocPhrDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdModelAssocPhrDict_MainStdDataModelDict_StdModelDictId",
                        column: x => x.StdModelDictId,
                        principalTable: "MainStdDataModelDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainStdModelAssocPhrDict_MainStdPhrDict_StdPhrDictID",
                        column: x => x.StdPhrDictID,
                        principalTable: "MainStdPhrDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdDataModelDict_TopicDictId",
                table: "MainStdDataModelDict",
                column: "TopicDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdEventModelDict_TopicDictId",
                table: "MainStdEventModelDict",
                column: "TopicDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelAssocPhrDict_StdModelDictId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelAssocPhrDict_StdPhrDictID",
                table: "MainStdModelAssocPhrDict",
                column: "StdPhrDictID");
        }
    }
}
